package org.example.erp.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.erp.domain.SysRoleMenu;
import org.example.erp.service.SysRoleMenuService;
import org.example.erp.mapper.SysRoleMenuMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author Administrator
* @description 针对表【sys_role_menu(角色菜单关联表)】的数据库操作Service实现
* @createDate 2024-11-06 12:40:13
*/
@Service
public class SysRoleMenuServiceImpl extends ServiceImpl<SysRoleMenuMapper, SysRoleMenu>
    implements SysRoleMenuService{

    public int saveGrant(Integer roleId, List<Integer> menuIds){
        //先删除当前角色拥有的全部权限
        int count = baseMapper.deleteByRoleId(roleId);
        //保存页面选中的权限
        for (Integer menuId : menuIds) {
            SysRoleMenu rm = new SysRoleMenu();
            rm.setRoleId(roleId);
            rm.setMenuId(menuId);
            baseMapper.insert(rm);
        }

        return count;
    }

}




